using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEditor.Experimental.GraphView;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;

namespace Framework.Fsm
{
    public class FsmGraphEditor : EditorWindow
    {
        private FsmGraphView _view;
        private FsmGraphContext _context;
        private FsmData _data;
        public static void CreateFsmWindow()
        {
            var window = GetWindow<FsmGraphEditor>();
        }
        private void OnEnable()
        {
            this.titleContent = new GUIContent("FSM Editor");
            this.minSize = new Vector2(1000, 600);
            _context = new FsmGraphContext();
            _context.Window = this;
            _view = new FsmGraphView(_context);
            _view.StretchToParentSize();
            rootVisualElement.Add(_view);
            if (_data != null)
            {
                _view.Open(_data);
            }
        }
        private void OnDisable()
        {
            if (_view != null)
            {
                rootVisualElement.Remove(_view);
            }
        }
        public void Initialize(FsmData value)
        {
            _data = value;
            if (_view != null)
            {
                _view.Open(_data);
            }
        }
    }
}